//
//  WebProgressView.swift
//  share
//
//  Created by NeXTSTEP on 16/4/27.
//  Copyright © 2016年 NeXTSTEP. All rights reserved.
//

import UIKit

class WebProgressView: UIView {


    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 64, width: 10, height: 2))
        backgroundColor = UIColor.blueColor()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("不支持xib加载该视图")
    }
    
    
    func startAnimation() {
        //增加长度
        self.alpha = 1
        UIView.animateWithDuration(0.3, animations: { () -> Void in
            self.frame.size.width = UIScreen.mainScreen().bounds.width * 0.4
            }) { (_) -> Void in
                UIView.animateWithDuration(0.3, animations: { () -> Void in
                    self.frame.size.width = UIScreen.mainScreen().bounds.width * 0.8
                }) 
        }
    }
    
    //结束动画
    func endAnimation() {
        UIView.animateWithDuration(0.3, animations: { () -> Void in
            self.frame.size.width = UIScreen.mainScreen().bounds.width
            }) { (finished) -> Void in
                if finished {
                    
                    self.alpha = 0
                    self.frame.size.width = 0
                }
        }
    }
 
}
